<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input type="text" v-model="keyword" placeholder="输入关键字"> <button @click="search">搜索</button>
        <ul>
            <!-- { "type": "sug", "sa": "s_1, "q": 111111"1转换十解释" },item.q可以搜索到关键字 -->
            <li v-for="item in result" :key="item.list">{{item.q}}</li>
        </ul>
    </div>
</body>
<script src="./vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script>
    // https://www.baidu.com/sugrec?ie=utf-8&json=1&prod=pc&wd=vue&req=2&csor=4&pwd=htm&cb=foo
    const vm = new Vue({
        // 控制器app
        el: "#app",
        data: {
            result: [],//搜索下拉的list
            keyword: ''//v-model双向绑定
        },
        methods: {
            search() {
                const _this = this;
                console.log(this);//vue的this
                $.ajax({
                    url: `https://www.baidu.com/sugrec?ie=utf-8&json=1&prod=pc&wd=${_this.keyword}&req=2&csor=4&pwd=htm`,//url
                    dataType: 'jsonp',//借助jquery jsonp来跨域请求
                    success(res) {
                         console.log(this);//url的this
                        _this.result = res.g
                    }
                })
            }
        },

    })
</script>

</html>